/**
 * Copyright (C) 2010 altuure <altuure [AT] gmail [DOT] com> http://www.altuure.com/projects/yagdao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.altuure.yagdao.dao;

import com.altuure.yagdao.*;
import com.altuure.yagdao.model.SimpleBean;

import java.util.Date;
import java.util.List;

/**
 * sample dao for test
 * @see SimpleBean
 */
public interface SimpleBeanDAO extends GenericDAO<SimpleBean, Long> {

    /**
     * Sample save method with two properties
     */
    @YMethod(type = YMethodType.SAVE)
    SimpleBean customSave1(@YParameter("pstring") String p1, @YParameter("pdouble") double p2);

    @YMethod(type = YMethodType.SAVE)
    SimpleBean customSave2(@YParameter("pstring") String pstring, @YParameter("pdouble") double pdouble,
            @YParameter("pdate") Date pdate, @YParameter("pint") int pint, @YParameter("pbyte") byte pbyte);

    @YMethod(type = YMethodType.UPDATE)
    SimpleBean customUpdate1(long id, @YParameter("pstring") String p1, @YParameter("pdouble") double p2);

    @YMethod(type = YMethodType.UPDATE)
    SimpleBean customUpdate2(long id, @YParameter("pstring") String pstring, @YParameter("pdouble") double pdouble,
            @YParameter("pdate") Date pdate, @YParameter("pint") int pint, @YParameter("pbyte") byte pbyte);

    @YMethod(type = YMethodType.QUERY, query = "select s from SimpleBean s")
    List<SimpleBean> customQuery1();

    @YMethod(type = YMethodType.QUERY, query = "select s from SimpleBean s where s.pint>:minint")
    List<SimpleBean> customQuery2(@YParameter("minint") int arg1);

    @YMethod(type = YMethodType.QUERY, query = "select s from SimpleBean s where s.pint>:minint")
    List<SimpleBean> customQuery2(@YParameter("minint") int arg1, YPage daoPage);

    @YMethod(type = YMethodType.QUERY, query = "select s from SimpleBean s where s.pint>:argint and s.pdate<=:argdate")
    List<SimpleBean> customQuery3(@YParameter("argint") int arg1, @YParameter("argdate") Date date);

    @YMethod(type = YMethodType.QUERY, query = "select s from SimpleBean s where s.pint>? and s.pdate<=?")
    List<SimpleBean> customQuery3Unnamed(int arg1, Date date);

    @YMethod(type = YMethodType.QUERY, query = "select s from SimpleBean s where s.pint>?1 and s.pdate<=?2")
    List<SimpleBean> customQuery3Unnamed2(int arg1, Date date);

    @YMethod(type = YMethodType.QUERY, query = "select s from SimpleBean s where s.pdate<=?2 and s.pint>?1 ")
    List<SimpleBean> customQuery3Unnamed3(int arg1, Date date);

    @YMethod(type = YMethodType.QUERY, query = "select s from SimpleBean s where s.pint>? and s.pdate<=? order by s.pint asc")
    List<SimpleBean> customQuery3Unnamed(int arg1, Date date, YLimit page);

    @YMethod(type = YMethodType.QUERY, queryName = "namedQuery1")
    List<SimpleBean> namedQuery1(@YParameter("arg1") int arg1);

    @YMethod(type = YMethodType.QUERY, queryName = "namedQuery1")
    List<SimpleBean> namedQuery1(@YParameter("arg1") int arg1, YLimit daoPage);

    @YMethod(type = YMethodType.QUERY, queryName = "namedQuery2")
    List<SimpleBean> namedQuery2(@YParameter("arg1") byte arg1);

    @YMethod(type = YMethodType.QUERY, queryName = "namedQuery2")
    List<SimpleBean> namedQuery2(@YParameter("arg1") byte arg1, YLimit daoPage);

    /**
     * Sample criteria builder
     * @param arg1 optional parameter 1
     * @return list of entities
     */
    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteria1(@YParameter(value = "pint", operator = YOperator.GE) Integer arg1);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteria1(@YParameter(value = "pint", operator = YOperator.GE) Integer arg1, YPage page);

    @YMethod(type = YMethodType.CRITERIA, select = "pint")
    SearchResultList<Object> criteriaSelected1(@YParameter(value = "pint", operator = YOperator.GE) Integer arg1);

    @YMethod(type = YMethodType.CRITERIA, select = "pint")
    SearchResultList<Object> criteriaSelected1_NEW1(@YParameter(value = "pint>=") Integer arg1);
  
    @YMethod(type = YMethodType.CRITERIA, select = "pint")
    SearchResultList<Object> criteriaSelected1_NEW2(@YParameter(value = "pint>=20000") boolean apply);

    @YMethod(type = YMethodType.CRITERIA, select =  "pint,pdate" )
    SearchResultList<Object[]> criteriaSelected2(@YParameter(value = "pint", operator = YOperator.GE) Integer arg1);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteria2(@YParameter(value = "pint", operator = YOperator.GE) Integer arg1,
            @YParameter(value = "pdate", operator = YOperator.LE) Date arg2

    );

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteria2(@YParameter(value = "pint", operator = YOperator.GE) Integer arg1,
            @YParameter(value = "pdate", operator = YOperator.LE) Date arg2, YPage page);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaBetween(@YParameter(value = "pint", operator = YOperator.BETWEEN) Integer[] arg);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaIn(@YParameter(value = "pint", operator = YOperator.IN) Integer[] arg);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaEqual(@YParameter(value = "pbyte", operator = YOperator.EQUAL) byte arg);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaNotEqual(
            @YParameter(value = "pbyte", operator = YOperator.EQUAL, not = true) byte arg);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaLE(@YParameter(value = "pint", operator = YOperator.LE) Integer arg);

    @YMethod(type = YMethodType.CRITERIA)
    List<SimpleBean> criteriaLTList(@YParameter(value = "pint", operator = YOperator.LT) Integer arg);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaLT(@YParameter(value = "pint", operator = YOperator.LT) Integer arg);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaGELT(@YParameter(value = "pint", operator = YOperator.GE) Integer min,
            @YParameter(value = "pint", operator = YOperator.LT) Integer maxE);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaGT(@YParameter(value = "pint", operator = YOperator.GT) Integer arg);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaGE(@YParameter(value = "pint", operator = YOperator.GE) Integer arg);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaULike(@YParameter(value = "pstring", operator = YOperator.ULIKE) String arg);

    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaLike(@YParameter(value = "pstring", operator = YOperator.LIKE) String arg);

    @YMethod(type = YMethodType.CRITERIA, orderBy = "pint desc")
    SearchResultList<SimpleBean> preDefinedOrder1(@YParameter(value = "pbyte", operator = YOperator.EQUAL) byte arg);

    @YMethod(type = YMethodType.CRITERIA, orderBy = "pint asc")
    SearchResultList<SimpleBean> preDefinedOrder2(@YParameter(value = "pbyte", operator = YOperator.EQUAL) byte arg,
            YLimit limits);

    @YMethod(type = YMethodType.CRITERIA, orderBy = "pint desc")
    SearchResultList<SimpleBean> preDefinedOrder3(@YParameter(value = "pbyte", operator = YOperator.EQUAL) byte arg,
            YPage page);

    @YMethod(type = YMethodType.COUNT)
    long count1(@YParameter(value = "pint", operator = YOperator.GE) Integer arg1);

    @YMethod(type = YMethodType.COUNT)
    long count2(@YParameter(value = "pint", operator = YOperator.GE) Integer arg1,
            @YParameter(value = "pdate", operator = YOperator.LE) Date arg2);

    @YMethod(type = YMethodType.EXECUTE,query = "update SimpleBean set pint=:newInt where id=:id ")
    int execute1(@YParameter(value = "newInt") int newInt,@YParameter(value = "id") long id);



    @YMethod(type = YMethodType.CRITERIA)
    SearchResultList<SimpleBean> criteriaEmptyString(@YParameter(value = "pstringNullable", operator = YOperator.EQUAL) String arg);

}
